﻿using LiveLinq;
using NUnit.Framework;
using System;
using SLE = System.Linq.Enumerable;

namespace LiveLinqTests
{
	[TestFixture]
	public class Where : AssertionHelper
	{
		[Test]
		public void QueryWhere()
		{
			var source = new[] { new Item(10), new Item(20), new Item(30), new Item(40), };

			Func<Item, bool> query = x => x.Width > 25;

			var actual = ObservableEnumerable.Where(source, query);

			Expect(actual != null);
			Expect(SLE.Count(actual) == 2);
			CollectionAssert.AreEqual(SLE.ToArray(SLE.Where(source, query)), SLE.ToArray(actual));

			source[1].Width = 26;

			Expect(SLE.Count(actual) == 3);
			CollectionAssert.AreEqual(SLE.ToArray(SLE.Where(source, query)), SLE.ToArray(actual));

			source[3].Width = 15;

			Expect(SLE.Count(actual) == 2);
			CollectionAssert.AreEqual(SLE.ToArray(SLE.Where(source, query)), SLE.ToArray(actual));
		}
	}
}